from Talk import Talk


class TraceNode:
    __talk: Talk
    __talks: list
    __lunchIndex: int
    __sortedTalks: list

    @property
    def lunchIndex(self):
        return self.__lunchIndex

    @lunchIndex.setter
    def lunchIndex(self, new):
        self.__lunchIndex = new

    def __init__(self, talk: Talk, last_node):
        self.__talk = talk
        self.__lastNode = last_node
        self.__talks = None
        self.__sortedTalks = None
        self.__lunchIndex = 0

    @property
    def talks(self):
        if self.__talks is None:
            node = self
            talks = []
            while node:
                talks.append(node.__talk)
                node = node.__lastNode
            self.__talks = talks
        return self.__talks

    @property
    def sortedTalks(self):
        if self.__sortedTalks is None:
            self.__sortedTalks = sorted(self.talks, key=lambda x: x.tag)
        return self.__sortedTalks